
package Interfaz;

import java.awt.event.*;
import javax.swing.JTextField;

public class Validacion {

    public void ValidarPalabras(JTextField caja) {
        caja.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent ke) {
                char c = ke.getKeyChar();
                if (!((Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (Character.isWhitespace(c))))) {
                    ke.consume();
                }
            }
        });
    }

    public void ValidarNumeros(JTextField caja) {
        caja.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent ke) {
                char c = ke.getKeyChar();
                if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE)))) {
                    ke.consume();
                }
            }
        });
    }   
    
    public void ValidarDecimales(JTextField caja) {
        caja.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent ke) {
                char caracter = ke.getKeyChar();
                if(((caracter < '0') || (caracter > '9')) && (caracter != KeyEvent.VK_BACK_SPACE)
                                && (caracter !='.')){
                /* lo que deseo colocar aqui es si ya se pulso el caracter (.) el mismo no se pueda repetir*/
                ke.consume();
                }
            }
        });
    }
    
    public void ValidarNumCasa(JTextField caja) {
        caja.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent ke) {
                char caracter = ke.getKeyChar();
                if(((caracter < '0') || (caracter > '9')) && (caracter != KeyEvent.VK_BACK_SPACE)
                                && (caracter !='-')){
                /* lo que deseo colocar aqui es si ya se pulso el caracter (.) el mismo no se pueda repetir*/
                ke.consume();
                }
            }
        });
    }
    
}
